<template>
  <div class="login">
    <h2>登录</h2>
    <form @submit.prevent="handleLogin">
      <input v-model="username" placeholder="用户名" required />
      <input v-model="password" type="password" placeholder="密码" required />
      <button type="submit">登录</button>
    </form>
  </div>
</template>

<script>
export default {
  data() {
    return {
      username: '',
      password: '',
    };
  },
  methods: {
    handleLogin() {
      if (this.username === 'admin') {
        localStorage.setItem('userRole', 'admin');
      } else {
        localStorage.setItem('userRole', 'student');
      }
      this.$router.push('/');
    },
  },
};
</script>